package export.monster
{
	import base.BaseMonster;
	
	import com.game.data.constant.FrameRate;
	
	import com.game.engine.MainGame;
	
	import com.game.manager.AnimationManager;
	
	import export.bullet.FollowTargetBullet;
	
	import flash.geom.Rectangle;
	//一阶牛魔王
	public class Monster402 extends BaseMonster
	{
		public function Monster402()
		{
			super();
		}
		
		private var turnBackInterval:int = FrameRate.ANIMATE_FRAME_RATE * 4;
		
		private var turnBackIntervalCount:uint = 0;
		
		override protected function initBBDC():void
		{
			bbdc = AnimationManager.getAnimation("Monster402Action");
			bbdc.setAction("idle");
			bbdc.turnRight();
			bbdc.addCallBack(onEnterFrame, onActionOver);
			bodyContainer.addChild(bbdc);
		}
		
		override protected function initCollideArea():void
		{
			collideBox = new Rectangle(-30,-90,60,90);
			super.initCollideArea();
		}
		
		override protected function initAttribute():void
		{
			super.initAttribute();
			mavo.attackRange = 150;
		}
		
		override protected function onEnterFrame(action:String, frameCount:int):void
		{
			if(magicBulletArray.length == 0)
			{
				var bu:FollowTargetBullet = new FollowTargetBullet("Monster402Bullet1");
				bu.setOwner(this);
				bu.setIsDestroyWhenLastFrame(false);
				bu.setCollideArea(-50,-60,100,60);
				bu.setHurt(getActionHurt("attack1"));
				bu.setDirect(bbdc.getDirect());
				bu.setAction("Monster402Attack1");
				gc.gameScene.addChild(bu);
				magicBulletArray.push(bu);
			}
		}
		
		override protected function attackTarget():void
		{
		
		}
		
		override public function isCanMoveWhenAttack():Boolean
		{
			return true;
		}
		
		override protected function myIntelligence() : void
		{
			if(bbdc.getAction() != "attack1" && bbdc.getAction() != "dead") setAction("attack1");
			if(isInScreen())
			{
				velocity.x = bbdc.getDirect() * 10;
			}
			else
			{
				velocity.x = 0;
			}
			turnBackIntervalCount++;
			if(turnBackIntervalCount >= turnBackInterval)
			{
				if(bbdc.getDirect() == 1)
				{
					turnLeft();
				}
				else
				{
					turnRight();
				}
				turnBackIntervalCount = 0;
			}
		}
		
		override protected function onActionOver(action:String):void
		{
			super.onActionOver(action);
			if(action == "dead") MainGame.getIns().createMonster(403,getCollideCenter().x,getCollideCenter().y - 100);
		}
	}
}/*package export.monster
{
	import base.BaseBitmapDataClip;
	import base.BaseBitmapDataPool;
	import base.BaseMonster;
	
	import com.dusk.util.ResUtil;
	import com.game.engine.MainGame;
	
	import export.bullet.FollowTargetBullet;
	
	import flash.display.Sprite;
	import flash.geom.Point;
	
	public class Monster402 extends BaseMonster
	{
		//一阶牛魔王
		
		private var turnBackInterval:int;
		
		private var turnBackIntervalCount:uint = 0;
		
		public function Monster402()
		{
			super();
			attackBackInfoDict["hit1"] = {
				"hitMaxCount":99,
				"attackBackSpeed":[0,0],
				"attackInterval":gc.frameClips,
				"attackKind":"physics"
			};
			turnBackInterval = gc.frameClips * 4;
			setAction("idle");
		}
		
		override protected function initBBDC() : void
		{
			var body:Object = null;
			var bmdArray:Array = BaseBitmapDataPool.getBitmapDataArrayByName("Monster402");
			if(bmdArray)
			{
				body = {
					"name":"body",
					"source":bmdArray
				};
				bbdc = new BaseBitmapDataClip([body],200,200,new Point(0,0));
				bbdc.setOffsetXY(-10,-25);
				bbdc.setFrameStopCount([[4,4,4,4]]);
				bbdc.setFrameCount([4]);
				bbdc.setEnterFrameCallBack(enterFrameFunc,exitFrameFunc);
				bbdc.setAddScriptWhenFrameOver(scriptFrameOverFunc);
				bodyContainer.addChild(bbdc);
				return;
			}
			throw new Error("Monster402--BitmapData Error!");
		}
		
		override protected function initCollideArea() : void
		{
			colipse = ResUtil.getNewObj("ObjectBaseSprite6") as Sprite;
			colipse.visible = false;
			addChild(colipse);
		}
		
		override public function setAction(str:String) : void
		{
			if(str != "dead" && str != "idle")
			{
				str = "idle";
			}
			super.setAction(str);
			var curPoint:Point = bbdc.getCurPoint();
			switch(str)
			{
				case "idle":
					if(curPoint.y != 0)
					{
						bbdc.setFramePointX(0);
						bbdc.setFramePointY(0);
					}
					bbdc.setState(str);
					break;
				case "dead":
					if(curPoint.y != 0)
					{
						bbdc.setFramePointX(0);
						bbdc.setFramePointY(0);
					}
					bbdc.setState(str);
			}
		}
		
		override protected function scriptFrameOverFunc(row:int) : void
		{
			var state:String = bbdc.getState();
			switch(state)
			{
				case "idle":
					bbdc.setFramePointX(0);
					break;
				case "dead":
					MainGame.getIns().createMonster(403,x,y - 200);
					dropAura();
					destroy();
			}
		}
		
		override protected function enterFrameFunc(p:Point) : void
		{
		}
		
		private function doHi1(direct:uint) : void
		{
			var b:FollowTargetBullet = new FollowTargetBullet("Monster402Bullet1");
			b.x = x;
			b.y = y;
			b.setIsDestroyWhenLastFrame(false);
			b.setIsDestroyWhenOwnerHurt(false);
			b.setDestroyInCount(gc.frameClips * 10);
			b.setOwner(this);
			b.setDirect(direct);
			b.setAction("hit1");
			gc.gameScene.addChild(b);
			magicBulletArray.push(b);
		}
		
		override protected function exitFrameFunc(p:Point) : void
		{
		}
		
		override protected function beforeSkill1Start() : Boolean
		{
			return true;
		}
		
		override protected function releSkill1() : void
		{
			doHi1(0);
		}
		
		override protected function hasAttackTarget() : void
		{
			if(beforeSkill1Start() && mavo.skillCD1[0] == 0)
			{
				releSkill1();
				mavo.skillCD1[0] = mavo.skillCD1[1];
			}
		}
		
		override protected function myIntelligence() : void
		{
			hasAttackTarget();
			if(isInScreen())
			{
				if(getBBDC().getDirect() == 0)
				{
					velocity.x = -10;
				}
				else
				{
					velocity.x = 10;
				}
			}
			else
			{
				velocity.x = 0;
			}
			if(turnBackIntervalCount < turnBackInterval)
			{
				turnBackIntervalCount++;
				if(turnBackIntervalCount == turnBackInterval)
				{
					if(getBBDC().getDirect() == 0)
					{
						turnRight();
					}
					else
					{
						turnLeft();
					}
					turnBackIntervalCount = 0;
				}
			}
		}
		
		override protected function attackTarget() : void
		{
		}
		
		override public function isCanMoveWhenAttack() : Boolean
		{
			return true;
		}
		
		override public function isAttacking() : Boolean
		{
			return curAction == "hit1";
		}
		
		override public function destroy() : void
		{
			super.destroy();
		}
	}
}
*/